/*     */ package com.qmsk.business.task.shareDiscuss.controller;
/*     */ 
/*     */ import com.qmsk.business.bussBill.bussBill.dao.BussBillDao;
/*     */ import com.qmsk.business.member.memberIntegralBill.dao.MemberIntegralBillDao;
/*     */ import com.qmsk.business.member.memberIntegralDetail.dao.MemberIntegralDetailDAO;
/*     */ import com.qmsk.business.member.memberIntegralRule.dao.MemberIntegralRuleDAO;
/*     */ import com.qmsk.business.member.shopMember.dao.ShopMemberDAO;
/*     */ import com.qmsk.business.task.shareDiscuss.dao.ShareDiscussBlackDao;
/*     */ import com.qmsk.business.task.shareDiscuss.dao.ShareDiscussDao;
/*     */ import com.qmsk.business.weixin.customMenu.weiXinUtil.WeiXinUtil;
/*     */ import com.utils.basic.ObjectComm;
/*     */ import com.utils.gson.in.GsonHeadOneRow;
/*     */ import com.utils.gson.in.ParserDataSetJson;
/*     */ import com.utils.gson.out.GsonEbRst;
/*     */ import com.utils.gson.out.GsonEbRstData;
/*     */ import com.utils.jdbc.connection.DbConnection;
/*     */ import com.utils.web.RequestUtils;
/*     */ import com.utils.web.ResponseUtils;
/*     */ import java.util.Date;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import org.apache.log4j.Logger;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.stereotype.Controller;
/*     */ import org.springframework.web.bind.annotation.RequestMapping;
/*     */ 
/*     */ @Controller
/*     */ @RequestMapping({"/shareDiscuss"})
/*     */ public class ShareDiscussController
/*     */ {
/*  38 */   private static final Logger logger = Logger.getLogger(ShareDiscussController.class);
/*     */ 
/*     */   @Autowired
/*     */   private ShareDiscussDao dao;
/*     */ 
/*     */   @Autowired
/*     */   private ShopMemberDAO shopMemberDAO;
/*     */ 
/*     */   @Autowired
/*     */   private MemberIntegralBillDao memberIntegralBillDao;
/*     */ 
/*     */   @Autowired
/*     */   private MemberIntegralDetailDAO memberIntegralDetailDAO;
/*     */ 
/*     */   @Autowired
/*     */   private MemberIntegralRuleDAO memberIntegralRuleDAO;
/*     */ 
/*     */   @Autowired
/*     */   private BussBillDao bussBillDao;
/*     */ 
/*     */   @Autowired
/*     */   private ShareDiscussBlackDao shareDiscussBlackDao;
/*     */ 
/*     */   @RequestMapping(value={"insert/insertInfo"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void insertInfo(HttpServletRequest request, HttpServletResponse response)
/*     */   {
/*     */     try
/*     */     {
/*  69 */       int nResult = 0;
/*  70 */       String openId = null;
/*  71 */       String sData = RequestUtils.getStringOfData(request);
/*  72 */       ParserDataSetJson p = ParserDataSetJson.fromString(sData);
/*  73 */       String agent = request.getHeader("User-Agent");
/*     */ 
/*  79 */       logger.error("111111111111111");
/*  80 */       if ((p != null) && (p.isExistsInsertRows())) {
/*  81 */         logger.error("22222");
/*  82 */         GsonHeadOneRow g = (GsonHeadOneRow)p.getListInsertRows().get(0);
/*  83 */         g.addHeadData("createdTime", new Date());
/*  84 */         openId = ObjectComm.objectToString(g.getValueOfName("openId"));
/*  85 */         Long shopId = ObjectComm.objectToLong(g.getValueOfName("shopId"));
/*  86 */         String ip = getIpAddr(request);
/*  87 */         String url = ObjectComm.objectToString(g.getValueOfName("url"));
/*  88 */         g.setValueOfName("ip", ip);
/*  89 */         logger.error("openId" + openId);
/*  90 */         logger.error("shopId" + shopId);
/*     */ 
/*  94 */         GsonHeadOneRow member = this.shopMemberDAO.getGsonOnRowOfShopIdAndOpenId(openId, shopId);
/*  95 */         if (member != null) {
/*  96 */           Long memberId = ObjectComm.objectToLong(member.getValueOfName("memberId"));
/*  97 */           if (this.dao.isBlackMeber(memberId) > 0) {
/*  98 */             g.addHeadData("memberId", memberId);
/*  99 */             logger.error("***************************************************" + agent);
/* 100 */             this.shareDiscussBlackDao.applyUpdates(p);
/* 101 */             DbConnection.commit();
/* 102 */             ResponseUtils.setSuccessResponse(response);
/* 103 */             return;
/*     */           }
/* 105 */           g.addHeadData("memberId", memberId);
/* 106 */           if (this.dao.checkExistByOpenId(openId, url, shopId, ip).intValue() <= 0) {
/* 107 */             String customerName = ObjectComm.objectToString(member.getValueOfName("customerName"));
/* 108 */             logger.error("转发分享");
/* 109 */             GsonEbRst intg = this.memberIntegralRuleDAO.getGsonOfName("转发分享");
/* 110 */             Integer intAmt = Integer.valueOf(0);
/* 111 */             String intAmtContent = "";
/* 112 */             if ((intg != null) && (intg.getDataLength() > 0)) {
/* 113 */               logger.error("有************");
/* 114 */               Long RuleID = (Long)intg.getResult().getValueOfIdx(0, "RuleID");
/* 115 */               intAmt = (Integer)intg.getResult().getValueOfIdx(0, "FixedIntegral");
/* 116 */               intAmtContent = ",您已获得" + intAmt + "个积分";
/* 117 */               Map params = new HashMap();
/* 118 */               params.put("memberId", memberId);
/* 119 */               params.put("shopId", shopId);
/* 120 */               params.put("intAmt", intAmt);
/* 121 */               nResult = this.shopMemberDAO.updateBissBillAmountInc(params);
/* 122 */               String billNO = this.bussBillDao.getMaxBillNo(shopId);
/* 123 */               String[] head = { "ShopID", "BillNo", "MemberID", "CustName", "GotIntAmt" };
/* 124 */               Object[] data = { shopId, billNO, memberId, customerName, intAmt };
/* 125 */               nResult = this.bussBillDao.insertGsonHeadOneRow(new GsonHeadOneRow(head, data));
/* 126 */               if (nResult > 0) {
/* 127 */                 Long billId = this.bussBillDao.getLastId();
/* 128 */                 nResult = this.memberIntegralBillDao.insertBsBillInAmtOfService(billNO, memberId, shopId, intAmt, RuleID, "转发分享", null, null, billId, null);
/* 129 */                 if (nResult > 0) {
/* 130 */                   String[] detilHead = { "ShopID", "Integral", "MemberID", "BillID", "Status" };
/* 131 */                   Object[] detilData = { shopId, intAmt, memberId, billId, Integer.valueOf(0) };
/* 132 */                   nResult = this.memberIntegralDetailDAO.insertGsonHeadOneRow(new GsonHeadOneRow(detilHead, detilData));
/*     */                 }
/*     */               }
/* 135 */               WeiXinUtil.sendTextMessageOfMain("尊敬的" + customerName + ":\n感谢您的分享" + intAmtContent, openId);
/*     */             }
/* 137 */             nResult = this.dao.applyUpdates(p);
/*     */           } else {
/* 139 */             nResult = 1;
/*     */           }
/*     */         }
/*     */       }
/*     */ 
/* 144 */       if (nResult > 0)
/* 145 */         DbConnection.commit();
/*     */       else {
/* 147 */         DbConnection.rollback();
/*     */       }
/*     */ 
/* 150 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 151 */         RequestUtils.getSqlInsertDataErrorMessage(request), 
/* 152 */         response);
/*     */     }
/*     */     catch (Exception e) {
/* 155 */       logger.error(e);
/* 156 */       DbConnection.rollback();
/* 157 */       ResponseUtils.setErrorMsgResponse(
/* 158 */         RequestUtils.getSqlInsertDataErrorMessage(request) + ":" + 
/* 159 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   public String getIpAddr(HttpServletRequest request) {
/* 164 */     String ip = request.getHeader("x-forwarded-for");
/* 165 */     if ((ip == null) || (ip.length() == 0) || ("unknown".equalsIgnoreCase(ip))) {
/* 166 */       ip = request.getHeader("Proxy-Client-IP");
/*     */     }
/* 168 */     if ((ip == null) || (ip.length() == 0) || ("unknown".equalsIgnoreCase(ip))) {
/* 169 */       ip = request.getHeader("WL-Proxy-Client-IP");
/*     */     }
/* 171 */     if ((ip == null) || (ip.length() == 0) || ("unknown".equalsIgnoreCase(ip))) {
/* 172 */       ip = request.getRemoteAddr();
/*     */     }
/* 174 */     return ip;
/*     */   }
/*     */ }

/* Location:           C:\Users\Administrator\Desktop\新建文件夹\WEB-INF\classes\
 * Qualified Name:     com.qmsk.business.task.shareDiscuss.controller.ShareDiscussController
 * JD-Core Version:    0.5.3
 */